package com.bqtv.sport.ui.mine

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.bqtv.sport.adapter.InviteRecordAdapter
import com.bqtv.sport.adapter.WithdrawnRecordAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.databinding.ActivityMyBaDouBinding
import com.hjq.bar.OnTitleBarListener
import com.hjq.bar.TitleBar

class MyBaDouActivity : AppActivity<ActivityMyBaDouBinding>() {
    private lateinit var inviteAdapter: InviteRecordAdapter
    private lateinit var withdrawnAdapter: WithdrawnRecordAdapter

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, MyBaDouActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding() = ActivityMyBaDouBinding.inflate(layoutInflater)

    override fun initView() {
        binding.rcvDetail.layoutManager = LinearLayoutManager(this)
        inviteAdapter = InviteRecordAdapter()
        binding.rcvDetail.adapter = inviteAdapter
        withdrawnAdapter = WithdrawnRecordAdapter()
    }

    override fun initData() {
        inviteAdapter.submitList(listOf("1", "2", "3", "4", "5", "6"))
        withdrawnAdapter.submitList(listOf("1", "2", "3", "4", "5", "6"))

        initListener()
    }

    private fun initListener() {
        getTitleBar()?.setOnTitleBarListener(object : OnTitleBarListener {
            override fun onRightClick(titleBar: TitleBar?) {
                super.onRightClick(titleBar)
                WithdrawnRulesActivity.start(this@MyBaDouActivity)
            }
        })
        withdrawnAdapter.setOnItemClickListener { adapter, view, position ->
            WithdrawnDetailActivity.start(this@MyBaDouActivity)
        }
        setOnClickListener(binding.tvWithdraw, binding.llInviteRecord, binding.llWithdrawnRecord)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view) {
            binding.tvWithdraw -> {
                WithdrawnActivity.start(this)
            }

            binding.llInviteRecord -> {
                binding.tvInviteRecord.setTextColor(Color.parseColor("#2F6146"))
                binding.tvWithdrawnRecord.setTextColor(Color.parseColor("#999999"))
                binding.vInviteRecord.visibility = View.VISIBLE
                binding.vWithdrawnRecord.visibility = View.INVISIBLE
                binding.rcvDetail.adapter = inviteAdapter
            }

            binding.llWithdrawnRecord -> {
                binding.tvWithdrawnRecord.setTextColor(Color.parseColor("#2F6146"))
                binding.tvInviteRecord.setTextColor(Color.parseColor("#999999"))
                binding.vWithdrawnRecord.visibility = View.VISIBLE
                binding.vInviteRecord.visibility = View.INVISIBLE
                binding.rcvDetail.adapter = withdrawnAdapter

            }

        }
    }
}